(function(){
	var list = document.getElementsByClassName("list")[0];
	var next = document.getElementById("next");
	var prev = document.getElementById("prev");
	var rounds = document.getElementsByTagName("span");
	var num = 0;
	function animation(n){
		for(var i = 0;i<rounds.length;i++){
			var round = rounds[i];
			if(round.className == "on"){
				round.className = "";
			};
			rounds[-n].className = "on";
		};
		list.style["left"] = n*640+"px";
	}
	next.onclick = function(){
		num--;
		if(num<-4){
			num = 0;
		};
		animation(num);
	}
	prev.onclick = function(){
		num++;
		if(num>0){
			num = -4;
		};
		animation(num);
	}
	var timer;
	function play(){
		timer = setInterval(function(){
			next.onclick();
		},3000);
	}
	function stop(){
		clearInterval(timer);
	}
	var container = document.getElementsByClassName("container")[0];
	container.onmouseout = play;
	container.onmouseover = stop;
	for(var i = 0;i<rounds.length;i++){
		rounds[i].addEventListener("click",function(){
			num = -parseInt(this.getAttribute("index"));
			animation(num);
		});
	}
})();